﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PRO_DOCS.DocumentManagementSystem.ADMIN.WIN.Configurations.Security
{
    public partial class ucModulesSecurity : BLL.WIN.Templates.DevxConfigurationUserControlTemplate
    {
        DAL.Database.APPLICATION_MODULE CURRENT_SELECTED_APPLICATION_MODULE
        { get; set; }
        public ucModulesSecurity()
        {
            InitializeComponent();

            btnAddNew.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            btnDeleteItem.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            btnSearch.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

            btnSaveUpdate.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btnSaveUpdate_ItemClick);

            List<DAL.Database.APPLICATION_MODULE> appModules = PRO_DOCSDatabaseDataContext.APPLICATION_MODULEs.ToList();
            gridControl1.DataSource = appModules;

            gridView1.ExpandAllGroups();
        }

        void btnSaveUpdate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //1. save denied users
            ucDeniedLoginUsers1.SAVE_DENIED_LOGIN_USERS(0, Guid.Empty, CURRENT_SELECTED_APPLICATION_MODULE.APPLICATION_MODULE_ID);
            //2. save permitted users
            ucPermittedLoginUsers1.SAVE_PERMITTED_LOGIN_USERS(0, Guid.Empty, CURRENT_SELECTED_APPLICATION_MODULE.APPLICATION_MODULE_ID);
            //3. save permitted roles
            ucPermittedUserRoles1.SAVE_PERMITTED_USER_ROLES(0, Guid.Empty, CURRENT_SELECTED_APPLICATION_MODULE.APPLICATION_MODULE_ID);
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle > -1)
            {
                CURRENT_SELECTED_APPLICATION_MODULE = gridView1.GetFocusedRow() as DAL.Database.APPLICATION_MODULE;

                //1. load denied Users
                ucDeniedLoginUsers1.LOAD_DENIED_LOGIN_USERS(ucBaseSecurity.SecurityOptions.ModulesSecurity, 0, Guid.Empty, CURRENT_SELECTED_APPLICATION_MODULE.APPLICATION_MODULE_ID);
                //2. load permitted users
                ucPermittedLoginUsers1.LOAD_PERMITTED_LOGIN_USERS(ucBaseSecurity.SecurityOptions.ModulesSecurity, 0, Guid.Empty, CURRENT_SELECTED_APPLICATION_MODULE.APPLICATION_MODULE_ID);
                //3. load permitted roles
                ucPermittedUserRoles1.LOAD_PERMITTED_USER_ROLES(ucBaseSecurity.SecurityOptions.ModulesSecurity, 0, Guid.Empty, CURRENT_SELECTED_APPLICATION_MODULE.APPLICATION_MODULE_ID);
            
            }
        }

    }
}
